<style scoped>
</style>
<template>
    <div style="text-align: center;" id="monitorTableBox">
        <slot name="header"></slot>
        <Table :loading="tableLoading" :columns="showColumns" :data="dataList" border :show-summary="showSummary" :summary-method="handleSummary">
            <template slot-scope="{ row, index }" slot="total">
                <monitor-detail-link :apply-no-set="row.total"/>
            </template>
            <template slot-scope="{ row, index }" slot="numWaitCheck">
                <monitor-detail-link :apply-no-set="row.numWaitCheck"/>
            </template>
            <template slot-scope="{ row, index }" slot="numParse">
                <monitor-detail-link :apply-no-set="row.numParse"/>
            </template>
            <template slot-scope="{ row, index }" slot="numReviseReply">
                <monitor-detail-link :apply-no-set="row.numReviseReply"/>
            </template>
            <template slot-scope="{ row, index }" slot="numCheck">
                <monitor-detail-link :apply-no-set="row.numCheck"/>
            </template>
            <template slot-scope="{ row, index }" slot="numReject">
                <monitor-detail-link :apply-no-set="row.numReject"/>
            </template>
            <template slot-scope="{ row, index }" slot="numCondition">
                <monitor-detail-link :apply-no-set="row.numCondition"/>
            </template>
            <template slot-scope="{ row, index }" slot="numCallback">
                <monitor-detail-link :apply-no-set="row.numCallback"/>
            </template>
            <template slot-scope="{ row, index }" slot="numAssertChange">
                <monitor-detail-link :apply-no-set="row.numAssertChange"/>
            </template>
            <template slot-scope="{ row, index }" slot="numFraudInspect">
                <monitor-detail-link :apply-no-set="row.numFraudInspect"/>
            </template>
            <template slot-scope="{ row, index }" slot="numRepertoryOverdue">
                <monitor-detail-link :apply-no-set="row.numRepertoryOverdue"/>
            </template>
            <template slot-scope="{ row, index }" slot="numReview">
                <monitor-detail-link :apply-no-set="row.numReview"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumReviseParse">
                <monitor-detail-link :apply-no-set="row.todayNumReviseParse"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumProcess">
                <monitor-detail-link :apply-no-set="row.todayNumProcess"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumAlreadyCheckFinal">
                <monitor-detail-link :apply-no-set="row.todayNumAlreadyCheckFinal"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumAlreadyConditionFinal">
                <monitor-detail-link :apply-no-set="row.todayNumAlreadyConditionFinal"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumAlreadyRejectFinal">
                <monitor-detail-link :apply-no-set="row.todayNumAlreadyRejectFinal"/>
            </template>
            <template slot-scope="{ row, index }" slot="todayNumAlreadyEnd">
                <monitor-detail-link :apply-no-set="row.todayNumAlreadyEnd"/>
            </template>
        </Table>
    </div>
</template>

<script>
    import {deepCopy} from "../../../../../../components/iview/utils/assist";
    import MonitorDetailLink from "./monitor-detail-link";
    export default {
        name: "aging-monitor",
        components: {MonitorDetailLink},
        props:{
            dataList:{
                type:Array,
                default: []
            },
            type:{
                type:String,
                default:""
            },
            showSummary:{
                type:Boolean,
                default:true
            }
        },
        data(){
            return {
                tableLoading:false,
                showColumns:[],
                columns:[
                    {
                        type: "index",
                        minWidth: 65,
                        fixed:"left",
                        key:"index",
                        align: "center"
                    },
                    {
                        title: "业务类型",
                        fixed:"left",
                        minWidth: 85,
                        key: "businessType",
                        align: "center"
                    },
                    {
                        title: "姓名",
                        fixed:"left",
                        minWidth: 90,
                        tooltip:true,
                        key: "realName",
                        align: "center"
                    },
                    {
                        title: "岗位状态",
                        minWidth: 85,
                        key: "postStatus",
                        fixed:"left",
                        align: "center"
                    },
                    {
                        title: "岗位",
                        minWidth: 90,
                        tooltip:true,
                        key: "jobPosition",
                        align: "center"
                    },
                    {
                        title: "总计",
                        minWidth: 70,
                        key: "total",
                        align: "center",
                        slot:"total"
                    },
                    {
                        title: "待审核",
                        minWidth: 75,
                        key: "numWaitCheck",
                        align: "center",
                        slot:"numWaitCheck"
                    },
                    {
                        title: "暂停",
                        minWidth: 65,
                        key: "numParse",
                        align: "center",
                        slot:"numParse"
                    },
                    {
                        title: "修订回复",
                        minWidth: 85,
                        key: "numReviseReply",
                        align: "center",
                        slot:"numReviseReply"
                    },
                    {
                        title: "建议核准",
                        minWidth: 85,
                        key: "numCheck",
                        align: "center",
                        slot:"numCheck"
                    },
                    {
                        title: "建议拒绝",
                        minWidth: 85,
                        key: "numReject",
                        align: "center",
                        slot:"numReject"
                    },
                    {
                        title: "建议附条件",
                        minWidth: 100,
                        key: "numCondition",
                        align: "center",
                        slot:"numCondition"
                    },
                    {
                        title: "撤回",
                        key: "numCallback",
                        minWidth: 65,
                        align: "center",
                        slot:"numCallback"
                    },
                    {
                        title: "资产变更",
                        minWidth: 85,
                        key: "numAssertChange",
                        align: "center",
                        slot:"numAssertChange"
                    },
                    {
                        title: "欺诈调查",
                        minWidth: 85,
                        key: "numFraudInspect",
                        align: "center",
                        slot:"numFraudInspect"
                    },
                    {
                        title: "库存超期",
                        minWidth: 85,
                        key: "numRepertoryOverdue",
                        align: "center",
                        slot:"numRepertoryOverdue"
                    },
                    {
                        title: "复议",
                        minWidth: 65,
                        key: "numReview",
                        align: "center",
                        slot:"numReview"
                    },
                    {
                        title: "修订暂停",
                        minWidth: 85,
                        key: "todayNumReviseParse",
                        align: "center",
                        slot:"todayNumReviseParse"
                    },
                    {
                        title: "已处理",
                        minWidth: 75,
                        key: "todayNumProcess",
                        align: "center",
                        slot:"todayNumProcess"
                    },
                    {
                        title: "已核准",
                        minWidth: 75,
                        key: "todayNumAlreadyCheckFinal",
                        align: "center",
                        slot:"todayNumAlreadyCheckFinal"
                    },
                    {
                        title: "附条件核准",
                        minWidth: 100,
                        key: "todayNumAlreadyConditionFinal",
                        align: "center",
                        slot:"todayNumAlreadyConditionFinal"
                    },
                    {
                        title: "已拒绝",
                        minWidth: 75,
                        key: "todayNumAlreadyRejectFinal",
                        align: "center",
                        slot:"todayNumAlreadyRejectFinal"
                    },
                    {
                        title: "出结果",
                        minWidth: 75,
                        key: "todayNumAlreadyEnd",
                        align: "center",
                        slot:"todayNumAlreadyEnd"
                    },
                    {
                        title: "平均时效",
                        minWidth: 85,
                        key: "agingAvg",
                        align: "center"
                    }
                ],
                finalSum:{},
                typeConst:{
                    leader:{
                        title:"组长监控",
                        val: "leader"
                    },
                    department:{
                        title:"部门监控",
                        val:"department"
                    }
                }
            }
        },
        methods:{
            dynamicColumns(){
                if(this.type==this.typeConst.leader.val){
                    this.columns.forEach(column=>{
                        if(column.key != "businessType" && column.key != "jobPosition"){
                            this.showColumns.push(column);
                        }
                    });
                }else{
                    this.columns.forEach(column=>{
                        this.showColumns.push(column);
                    })
                }
            },
            startLoading(){
                this.tableLoading = true;
            },
            endLoading(){
                this.tableLoading = false;
            },
            getShowColumns(){
              return deepCopy(this.showColumns);
            },
            handleSummary({columns,data}){
                const sums = {};
                columns.forEach((column, index) => {
                    const key = column.key;
                    if (index === 0) {
                        sums[key] = {
                            key,
                            value: '总计'
                        };
                        this.finalSum[key] = '总计';
                        return;
                    }
                    const values = data.map(item => {
                        const val = item[key];
                        return val instanceof  Array ? val.length : Number(val);
                    });
                    if (!values.every(value => isNaN(value))) {
                        const v = values.reduce((prev, curr) => {
                            const value = Number(curr);
                            if (!isNaN(value)) {
                                return prev + curr;
                            } else {
                                return prev;
                            }
                        }, 0);
                        sums[key] = {
                            key,
                            value: v + ''
                        };
                        this.finalSum[key] = v;
                    } else {
                        sums[key] = {
                            key,
                            value: ''
                        };
                        this.finalSum[key] = '';
                    }
                });
                this.$emit("on-end-summary",deepCopy(this.finalSum));
                return sums;
            }
        },
        mounted() {
            this.dynamicColumns();
        }
    }
</script>
